package com.zzyk.main.service.impl;

import com.zzyk.main.mapper.AreaMapper;
import com.zzyk.main.model.pojo.Area;
import com.zzyk.main.service.AreaService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class AreaServiceImpl implements AreaService {

    @Resource
    private AreaMapper areaMapper;

    @Override
    public int deleteByPrimaryKey(Integer areaid) {
        return areaMapper.deleteByPrimaryKey(areaid);
    }

    @Override
    public int insert(Area record) {
        return areaMapper.insert(record);
    }

    @Override
    public int insertSelective(Area record) {
        return areaMapper.insertSelective(record);
    }

    @Override
    public Area selectByPrimaryKey(Integer areaid) {
        return areaMapper.selectByPrimaryKey(areaid);
    }

    @Override
    public int updateByPrimaryKeySelective(Area record) {
        return areaMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Area record) {
        return areaMapper.updateByPrimaryKey(record);
    }

    @Override
    public List<Area> selectProvince() {
        return areaMapper.selectAllByArealevel(1);
    }

    @Override
    public List<Area> selectAllByProvince(String province) {
        if (StringUtils.isBlank(province)) {
            return null;
        }
        Area area = areaMapper.selectAllByAreaname(province);
        return areaMapper.selectAllByParentid(area.getAreaid());
    }

    @Override
    public List<Area> selectAllByCity(String city,String province) {
        if (StringUtils.isBlank(city)) {
            return null;
        }
        Area area = areaMapper.selectAllByAreaname(province);
        Area area2 = areaMapper.selectByAreaNameAndParentId(city,area.getAreaid());
//        Area area = areaMapper.selectAllByAreaname(city);
        return areaMapper.selectAllByParentid(area2.getAreaid());
    }
}
